package com.lsq.lwf.common.utils;

import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

public class PropertiesUtils {

	private static Properties prop = new Properties();
	private static HashMap<String, String> map = new HashMap<String, String>();
	public static String fileName;
	
	static {
		init();
	}

	private static void init() {
		try {
			prop.load(PropertiesUtils.class.getClassLoader().getResourceAsStream("dbcpconfig.properties"));

			Enumeration<Object> e = prop.keys();
			while (e.hasMoreElements()) {
				String key = (String) e.nextElement();
				String value = prop.getProperty(key);
				map.put(key, value);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String getValue(String key) {
		if (StringUtils.isNotBlank(map.get(key))) {
			return map.get(key);
		} else {
			return prop.getProperty(key);
		}
	}

	public static void setValue(String value) {
		prop.setProperty("init", value);
	}
}
